

#include "DFRobot_DS3231M.h"
#include "time.h"
#include <U8g2lib.h>

DFRobot_DS3231M rtc;
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);

void page1()
{
  u8g2.setFont(u8g2_font_timB18_tf);
  u8g2.setFontPosTop();
  u8g2.setCursor(10, 10);
  u8g2.print(String(rtc.year()) + String("-") + String(rtc.month() / 10 % 10) + String(rtc.month() % 10) + String("-") + String(rtc.day() / 10 % 10) + String(rtc.day() % 10));
  u8g2.setCursor(22, 40);
  u8g2.print(String(rtc.hour() / 10 % 10) + String(rtc.hour() % 10) + String(":") + String(rtc.minute() / 10 % 10) + String(rtc.minute() % 10) + String(":") + String(rtc.second() / 10 % 10) + String(rtc.second() % 10));
}

void setup()
{
  while (rtc.begin() != true)
  {
  }

  u8g2.begin();
  u8g2.enableUTF8Print();
}

void loop()
{
  rtc.getNowTime();
  /*Serial.print(rtc.year(), DEC);//year
    Serial.print('/');
    Serial.print(rtc.month(), DEC);//month
    Serial.print('/');
    Serial.print(rtc.day(), DEC);//date
    Serial.print(" (");
    Serial.print(rtc.getDayOfTheWeek());//day of week
    Serial.print(") ");
    Serial.print(rtc.hour(), DEC);//hour
    Serial.print(':');
    Serial.print(rtc.minute(), DEC);//minute
    Serial.print(':');
    Serial.print(rtc.second(), DEC);//second
    Serial.println();
    delay(1000); */

  u8g2.firstPage();
  do
  {
    page1();
  } while (u8g2.nextPage());
}
